package com.hwd.srb.core.util;

import com.hwd.srb.core.enmu.ReturnMethodEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 黄伟东/Victor
 * @date 2022/3/31 23:40
 * @Description
 */
public class AmountHelperMapping {

    private Map<String, AmountHelper> amountHelperMethods = new HashMap<>();

    public void initHelperMethods() {
        amountHelperMethods.put(ReturnMethodEnum.EQUALITY_CORPUS_AND_INTEREST.getReturnMethod(), new Amount1Helper());
        amountHelperMethods.put(ReturnMethodEnum.EQUALITY_CORPUS.getReturnMethod(), new Amount2Helper());
        amountHelperMethods.put(ReturnMethodEnum.PER_MONTH_INTEREST_AND_ONCE_CORPUS.getReturnMethod(), new Amount3Helper());
        amountHelperMethods.put(ReturnMethodEnum.ONCE_CORPUS_AND_INTEREST.getReturnMethod(), new Amount4Helper());
    }

    public AmountHelper getAmountHelper(String returnMethod) {
        if (this.amountHelperMethods != null) {
            return this.amountHelperMethods.entrySet().stream()
                    .filter(i -> i.getKey().equals(returnMethod))
                    .map(Map.Entry::getValue)
                    .findFirst()
                    .orElse(null);
        }
        return null;
    }

}
